<template>
  <div class="main">
    <div class="title-box">
      <Titile desc="名人" @clickMore="clickMore"/>
    </div>
    <el-empty description="暂无数据" :image-size="200" v-if="!state.list.length"/>
    <div class="person-list dispaly-center" v-else>
<!--      singleLine-->
      <SeamlScroll :speed="50" :interval="2000" >
        <div class="item pointer" v-for="(item, index) in state.list" :key="index" @click="skipDetail(item)">
          <div class="avatar-box">
            <img :src="item.img">
            <div class="dispaly-align-center">
              <div class="name dispaly-align-center">{{ item.title }}</div>
            </div>
          </div>
        </div>
      </SeamlScroll>
    </div>
  </div>
</template>


<script setup>
import Titile from '@/components/title.vue'
import {reactive, onMounted} from 'vue'
import {getIndexCelebrity, getCelebrityList} from '@/api/index/index'
import {useRouter} from 'vue-router';
import SeamlScroll from "@/views/home/components/seamlScroll.vue";

const state = reactive({
  list: [],
  queryData: {
    pageNum: 1,
    pageSize: 999,
    type: 0
  }
})

// 首页推荐
const getIndexArticleData = async () => {
  const res = await getCelebrityList(state.queryData)
  if (res.code == 200) {
    state.list = res.rows
    state.list.forEach(item => {
      item.title = item.firstName + item.lastName
    })
  }
}

onMounted(() => {
  getIndexArticleData()
})

// 点击更多
const router = useRouter()
const clickMore = () => {
  localStorage.setItem('tabIndex', 3)
  router.push({
    path: '/celebrity'
  })
}

// 跳转详情
const skipDetail = (item) => {
  router.push({
    path: '/detail',
    query: {id: item.id, type: 'person', tValue: item.type}
  })
}

</script>
<style scoped lang="scss">

.main {
  .person-list {
    margin-top: 20px;
    height: 191px;
    overflow: scroll;
    .item:last-child {
      margin-right: 0;
    }

    .item {
      margin-right: 17px;
      border-radius: 5px;
      .avatar-box {
        width: 142px;
        height: 191px;
        border-radius: 5px;
        position: relative;

        .name:hover {
          color: $primary-color;
        }

        .name {
          position: absolute;
          bottom: 10px;
          background: #FFFFFF;
          border-radius: 5px;
          padding: 9px 35px;
          font-family: MicrosoftYaHei;
          font-size: 14px;
          color: #333333;
        }

        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
      }
    }
  }
}
</style>